package bancosys.tec.security.impl.services.incluir;

import java.util.List;

import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.annotations.WithPreffix;
import jmine.tec.services.api.ActionsEnum;
import bancosys.tec.security.impl.domain.Group;
import bancosys.tec.security.impl.domain.MetaCredential;

/**
 * Service to associate a list of Meta Crential to a group.
 * 
 * @author stephen.ribeiro
 * @created Jun 19, 2012
 */
@ServiceImplementor(action = ActionsEnum.INCLUIR)
public class GroupMetaCredentialListService {

	public static final String META_CREDENTIAL = "Meta_Credential";
	
	public static final String GROUP = "Group";
	
	private List<MetaCredential> metaCredentials;
	
	private Group group;
	
	/**
	 * Execute the service 
	 */
	@Execution
	public void execute() {
	    
	    for(MetaCredential meta: this.metaCredentials){
	        this.group.getCredentials().addAll(meta.getCredentials());
	    }
	    
 		this.group.getPersister().save();
	}

	/**
	 * @param metaCreds to set
	 */
	@WithPreffix(preffix=META_CREDENTIAL)
	public void setMetaCredentials(List<MetaCredential> metaCreds) {
		this.metaCredentials = metaCreds;
	}
	
	/**
	 * @param group to set
	 */
	@Input(fieldName = GROUP)
	public void setGroup(Group group) {
		this.group = group;
	}
}